package com.hrm.houfei.dao.impl;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.hrm.houfei.dao.IEngageinforeleaseDAO;
import com.hrm.houfei.po.Engageinforelease;

/**
 * A data access object (DAO) providing persistence and search support for
 * Engageinforelease entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.hrm.houfei.po.Engageinforelease
 * @author MyEclipse Persistence Tools
 */

public class EngageinforeleaseDAO extends HibernateDaoSupport implements
		IEngageinforeleaseDAO {
	private static final Log log = LogFactory
			.getLog(EngageinforeleaseDAO.class);

	protected void initDao() {
		// do nothing
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IEngageinforeleaseDAO#save(com.hrm.houfei.po.Engageinforelease)
	 */
	public void save(Engageinforelease transientInstance) {
		log.debug("saving Engageinforelease instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IEngageinforeleaseDAO#delete(com.hrm.houfei.po.Engageinforelease)
	 */
	public void delete(Engageinforelease persistentInstance) {
		log.debug("deleting Engageinforelease instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/**
	 * 多条件分页模糊查询
	 * 
	 * @param criteria
	 *            离线查询
	 * @param firstResult
	 *            索引
	 * @param maxResults
	 *            每页要显示的记录的条数
	 * @return 当前页的所有记录 List<Engageinforelease>
	 */
	public List<Engageinforelease> findAllByPageCondition(
			DetachedCriteria criteria, int firstResult, int maxResults) {
		return super.getHibernateTemplate().findByCriteria(criteria,
				firstResult, maxResults);
	}

	/**
	 * 根据条件获取查询结果的记录条数
	 * @param criteria 离线查询
	 * @return 总记录的条数(条件)
	 */
	public int getPageListCount(DetachedCriteria criteria) {
		return super.getHibernateTemplate().findByCriteria(criteria).size();
	}
	
	/**
	 * 修改Engageinforelease
	 * @param entity
	 */
	public void update(Engageinforelease entity){
		try {
			super.getHibernateTemplate().update(entity);	
		} catch (RuntimeException re) {
			throw re;
		}
		
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IEngageinforeleaseDAO#findById(java.lang.Integer)
	 */
	public Engageinforelease findById(java.lang.Integer id) {
		log.debug("getting Engageinforelease instance with id: " + id);
		try {
			Engageinforelease instance = (Engageinforelease) getHibernateTemplate()
					.get("com.hrm.houfei.po.Engageinforelease", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IEngageinforeleaseDAO#findByExample(com.hrm.houfei.po.Engageinforelease)
	 */
	public List findByExample(Engageinforelease instance) {
		log.debug("finding Engageinforelease instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IEngageinforeleaseDAO#findByProperty(java.lang.String,
	 *      java.lang.Object)
	 */
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Engageinforelease instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from Engageinforelease as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IEngageinforeleaseDAO#findAll()
	 */
	public List findAll() {
		log.debug("finding all Engageinforelease instances");
		try {
			String queryString = "from Engageinforelease";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IEngageinforeleaseDAO#merge(com.hrm.houfei.po.Engageinforelease)
	 */
	public Engageinforelease merge(Engageinforelease detachedInstance) {
		log.debug("merging Engageinforelease instance");
		try {
			Engageinforelease result = (Engageinforelease) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IEngageinforeleaseDAO#attachDirty(com.hrm.houfei.po.Engageinforelease)
	 */
	public void attachDirty(Engageinforelease instance) {
		log.debug("attaching dirty Engageinforelease instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hrm.houfei.dao.impl.IEngageinforeleaseDAO#attachClean(com.hrm.houfei.po.Engageinforelease)
	 */
	public void attachClean(Engageinforelease instance) {
		log.debug("attaching clean Engageinforelease instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static IEngageinforeleaseDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (IEngageinforeleaseDAO) ctx.getBean("EngageinforeleaseDAO");
	}
}